package xijia.plus.docs.thymeleafuser.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import xijia.plus.docs.thymeleafuser.service.PageService;
import xijia.plus.docs.thymeleafuser.constant.PageEnum;

import javax.servlet.http.HttpServletRequest;


/**
 * 页面访问
 *
 * @author wangsong
 * @version 1.0.0
 * @mail 1720696548@qq.com
 * @date 2022/10/13 0013 20:37
 */
@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    @Autowired
    private HttpServletRequest request;

    /**
     * 首页 入口
     *
     * @return
     */
    @RequestMapping("/")
    public String home(Model model) {
        // 重定向到 index
        return "redirect:" + PageEnum.INDEX.getPage();
    }


    /**
     * 首页 入口
     *
     * @return
     */
    @RequestMapping("/index.html")
    public String index(Model model) {
        return pageService.home(model);
    }


    /**
     * 别名访问入口
     * <p>
     * 分类 + 文章 + 产品
     * </P>
     *
     * @param categoryName
     * @param name,
     * @param model
     * @return
     */
    @RequestMapping(value = "/{categoryName}/{name}.html")
    public String findByName(@PathVariable String categoryName, @PathVariable String name, Model model) {
        return pageService.findByName(model, categoryName, name);
    }

}

